from Tools import *
import Global

class Account:
    def __init__(self):
        self.id = 0
        self.name = ''
        self.showable = True

class AccountType:
    Cash = 1
    Debt = 2
    Redebt = 3

class RecordType:
    Income = 1
    Payment = 2
    Transfer = 3
    
class OtherRecordType: # CAT1
    BorrowIn = 1
    ReturnBack = 2
    LendOut = 3
    ReturnIn = 4

class Cat1:
    def __init__(self):
        self.id = 0
        self.name = ''
        self.showable = 0
        self.cat2List = []  # index不是cat2Id
    def clear(self):
        self.id = 0
        self.name = ''
        self.showable = 0
        self.cat2List = []

class Cat2:
    def __init__(self):
        self.id = 0
        self.cat1Id = 0
        self.name = ''
        self.showable = 0
    def clear(self):
        self.id = 0
        self.cat1Id = 0
        self.name = ''
        self.showable = 0

class Cat2Simple:
    def __init__(self):
        self.name = ''
        self.cat1Id = 0

class Category :
    def __init__(self) :
        self.incomeCat1 = []    # cat1Id就是index，第0個元素不使用，值為None
        self.paymentCat1 = []   # cat1Id就是index，第0個元素不使用，值為None
        self.paymentCat2 = []   # cat2Id就是index，第0個元素不使用，值為None，Cat2Simple类型
        self.otherCat1 = []     # cat1Id就是index，第0個元素不使用，值為None
        

class IncomeRecord:
    def __init__(self):
        self.time = 0
        self.accountId = 0
        self.cat1Id = 0
        self.amount = 0
        self.description = ''
    def __str__(self):
        s = 'TIME:        ' + timestampToString(self.time) + '\n' \
          + 'ACCOUNT:     ' + Global.accounts[self.accountId].name + '\n' \
          + 'CATEGORY:    ' + Global.categorys.incomeCat1[self.cat1Id].name + '\n' \
          + 'AMOUNT:      %s'%(fenToYuanStr(self.amount)) + '\n' \
          + 'DESCRIPTION: ' + self.description
        return s

class PaymentRecord:
    def __init__(self):
        self.time = 0
        self.accountId = 0
        self.cat1Id = 0
        self.cat2Id = 0
        self.amount = 0
        self.description = ''
    def __str__(self):
        s = 'TIME:        ' + timestampToString(self.time) + '\n' \
          + 'ACCOUNT:     ' + Global.accounts[self.accountId].name + '\n' \
          + 'CATEGORY:    %s => %s'%\
            (Global.categorys.paymentCat1[self.cat1Id].name,\
            Global.categorys.paymentCat2[self.cat2Id].name) + '\n' \
          + 'AMOUNT:      %s'%(fenToYuanStr(self.amount)) + '\n' \
          + 'DESCRIPTION: ' + self.description
        return s

class TransferRecord:
    def __init__(self):
        self.time = 0
        self.amount = 0
        self.cat1Id = 0
        self.srcAccountId = 0
        self.dstAccountId = 0
        self.desctiption = 0
    def __str__(self):
        s = 'TIME:           ' + timestampToString(self.time) + '\n' \
          + 'CATEGORY:       ' + Global.categorys.transferCat1[self.cat1Id].name + '\n' \
          + 'AMOUNT:         %s'%(fenToYuanStr(self.amount)) + '\n' \
          + 'SRC ACCOUNT:    ' + Global.accounts[self.srcAccountId].name + '\n' \
          + 'DST ACCOUNT:    ' + Global.accounts[self.dstAccountId].name + '\n' \
          + 'DESCRIPTION:    ' + self.description
        return s

class TimeLength:
    Day = 1
    Month = 2
    Year = 3
    
class TransferCat1Id:
    BorrowIn = 1
    ReturnBack = 2
    LendOut = 3
    ReturnIn = 4
    Other = 5

class DefaultAccountId:
    Cash = 1
    Debt = 2
    Redebt = 3

class BudgetItem:
    '''用於表示每個一級支出分類的全年預算和各個月的預算'''
    def __init__(self):
        self.name = ''
        self.year = 0
        self.month = [None,0,0,0,0,0,0,0,0,0,0,0,0] #第0個元素不使用
    def setMonthBudget(self, month, value):
        if value < 1 or value > 12:
            raise ValueError()
        sef.month[month] = value
    def setYearBudget(self, value):
        self.year = value
    def setAll(self, year, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12):
        self.year = year
        self.month = [None,m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12]

class AOFRecordType:
    AddIncomeRecord = 1
    AddPaymentRecord = 2
    AddTransferRecord = 3
    EditIncomeRecord = 4
    EditPaymentRecord = 5
    EditTransferRecord = 6
    DeleteIncomeRecord = 7
    DeletePaymentReocrd = 8
    DeleteTransferRecord = 9
    AddPaymentCat1 = 10
    EditPaymentCat1 = 11
    DeletePaymentCat1 = 12
    AddPaymentCat2 = 13
    EditPaymentCat2 = 14
    DeletePaymentCat2 = 15
    SetBudget = 16
